//
//  BN_MyInfoHelperTest.m
//  BabyNow
//
//  Created by 闫建刚 on 14-5-26.
//  Copyright (c) 2014年 iMobile. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "XCTestAsync.h"
#import "BN_MyInfoHelper.h"

@interface BN_MyInfoHelperTest : XCTestCase
{
    BN_MyInfoHelper *myInfoHelper_;
}
@end

@implementation BN_MyInfoHelperTest

- (void)setUp
{
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
    myInfoHelper_ = [[BN_MyInfoHelper alloc]init];
    
}

- (void)tearDown
{
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
    myInfoHelper_ = nil;
}

- (void)xctAssertNil:(NSString *)errorMsg{
    XCTAssertNil(errorMsg);
}

- (void)xcAsyncSuccess{
    XCAsyncSuccess();
}

// 测试获取家长首页信息
- (void)testQueryParentHomeInfoAsync{
     __weak typeof(self) weakSelf = self;
    
    myInfoHelper_.queryParentHomeListCompleteHandler = ^(id result,NSString *errMsg){
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"家长首页信息：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    };
    [myInfoHelper_ refreshParentHomeInfoList];
    
    /*[myInfoHelper_ queryParentHomeInfo:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"家长首页信息：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];*/
}

// 测试获取勋章详细信息
- (void)testQueryMedalListAsync{
    __weak typeof(self) weakSelf = self;
    [myInfoHelper_ queryMedalList:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"勋章详细信息：%@",result);
            [weakSelf xcAsyncSuccess];
        }

    }];
}

// 查询宝宝列表信息
- (void)testQueryChildListAsync{
    __weak typeof(self) weakSelf = self;
    [myInfoHelper_ queryChildList:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"宝宝列表信息：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}

// 测试查询勋章类型列表信息
// - (void)queryMedalTypeListAsync {
- (void)testQueryMedalTypeListAsync {
    __weak typeof (self) weakSelf = self;
    NSString *childId = @"1";
    [myInfoHelper_ queryMedalTypeListForChildId:childId completeHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"勋章类型列表信息：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}

// 测试颁发勋章
- (void)testSendMedalInfoAsync{
    __weak typeof(self) weakSelf = self;
    NSString *childId = @"1";
    NSString *medalId = @"3";
    [myInfoHelper_ sendMedalInfoForChildId:childId medalId:medalId completeHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"测试颁发勋章结果：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}

// 测试查询周评列表
- (void)testQueryEvalListAsync{
    __weak typeof (self) weakSelf = self;
    NSString *childId = @"1";
    myInfoHelper_.queryEvalListCompleteHandler = ^(id result,NSString *errMsg){
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"周评列表信息：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    };
    [myInfoHelper_ refreshEvalList:childId];
}

// 测试发布周评
- (void)testSendEvalInfoAsync{
    __weak typeof (self) weakSelf = self;
    NSString *childId = @"1";
    NSString *evalCont = @"2014-06-04 测试发布周评";
    [myInfoHelper_ sendEvaLInfoForChildId:childId evalCont:evalCont completeHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"周评发布结果：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}


// 测试查询教师首页信息
- (void)testQueryTeacherHomeInfoAsync{
    __weak typeof (self) weakSelf = self;
    [myInfoHelper_ queryTeacherHomeInfo:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"教师首页信息：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}

// 查询积分列表
- (void)testQueryPrizListAsync{
    __weak typeof (self) weakSelf = self;
    [myInfoHelper_ queryPrizList:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"积分列表信息：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}

// 测试兑换积分
- (void)testPrizChangeAsync{
    __weak typeof(self) weakSelf = self;
    NSString *prizId = @"1";
    NSString *pointNum = @"60";
    [myInfoHelper_ prizChangeWithPrizId:prizId pointNum:pointNum completeHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"积分兑换结果：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}

// 测试查询积分规则
- (void)testQueryPointRuleAsync{
    __weak typeof(self) weakSelf = self;
    [myInfoHelper_ queryPointRule:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"积分规则信息：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}

// 测试查询个人资料
- (void)testQueryUserInfoAsync{
    __weak typeof (self) weakSelf = self;
    [myInfoHelper_ queryUserInfo:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"个人资料信息：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}

// 测试更新个人资料
- (void)testUpdateUserInfoAsync{
    __weak typeof (self) weakSelf = self;
    
    NSString *birthDate = @"1976-10-01";
    NSString *gradUniv  = @"";
    NSString *educ = @"";
    NSString *sign = @"";
    NSString *phone = @"18612345678";
    
    [myInfoHelper_ updateUserInfoWithBirthDate:birthDate gradUniv:gradUniv educ:educ sign:sign phone:phone completeHandle:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"更新个人资料结果：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}

// 测试更新个人资料 加头像
- (void)testUpdataUserPhotoInfoAsync {
    
    __weak typeof(self) weakSelf = self;

    NSString *birthDate = @"1991-11-11";
    NSString *gradUniv  = @"1";
    NSString *educ = @"1";
    NSString *sign = @"1";
    NSString *phone = @"1";
    
    NSString *fileName1 = @"ios8.png";
    NSString *imgPath1 = [[NSBundle mainBundle]pathForResource:@"userPhoto" ofType:@"png"];
    NSData *imgData1 = [NSData dataWithContentsOfFile:imgPath1];
    
    // 封装1张图片
    NSArray *fileInfoArr = @[@{kFileName:fileName1,kFileData:imgData1,kFileMimeType:FILE_MIME_TYPE_FOR_PNG}];

    // 请求网络
    [myInfoHelper_ updateUserInfoWithBirthDate:birthDate gradUniv:gradUniv educ:educ sign:sign phone:phone filesInfoArr:fileInfoArr completeHandle:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else {
            [weakSelf xcAsyncSuccess];
        }
    } uploadProcessingHandler:^(double process) {
        NSLog(@"上传进度:%f",process);
    }];
    
}

// 测试更新用户密码
- (void)testUpdateUserPasswordAsync{
    __weak typeof(self) weakSelf = self;
    NSString *newPass = @"123456";
    [myInfoHelper_ updateUserInfoWithNewPass:newPass completeHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"用户密码更新结果：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}

// 测试更新绑定邮箱
- (void)testUpdateUserMailAsync{
    __weak typeof(self) weakSelf = self;
    NSString *mail = @"xiaobao@163.com";
    [myInfoHelper_ updateUserInfoWithMail:mail completeHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"绑定邮箱更新结果：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}




@end
